<template>
  <div>
    很好
    <el-button type="primary" @click="dialogVisible = true">测试按钮</el-button>
    <!-- 对话框 -->
    <TodoDialog
      :dialogTitle="dialogTitle"
      :visible.sync="dialogVisible"
      :dialogData="dialog_data"
      :dialogItem="dialog_item"
      @updateVisible="updateVisible"
      @resetPopupData="resetPopupData"
      @submitPopupData="submitPopupData"
      @handleClose="handleClose"
      @handlechangeVal="changeValData"
      :popupWidth="'550px'"
    >
    </TodoDialog>
    <!-- 九宫格 -->
    <div class="content">
      <ul>
        <li
          :style="randomRgb()"
          v-for="item in listData"
          :key="item.id"
          @click="getData(item)"
        >
          <span>{{ item.id }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { testData } from "@/content/index";
import TodoDialog from "@/components/TodoDialog/index.vue";
export default {
  name: "ConsoleIndex",
  components: { TodoDialog },
  data() {
    return {
      dialogVisible: false, // 弹框的出现与否
      dialogTitle: "", // 标题
      listData: testData,
      content: "",
      dialog_data: {
        carsMode: "",
        textareaId: "",
      },
      dialog_item: [
        {
          type: "Input",
          label: "车辆型号",
          placeholder: "请输入车辆型号",
          prop: "carsMode",
          width: "100px",
        },
        {
          type: "textarea",
          label: "车辆型号",
          placeholder: "请输入",
          prop: "textareaId",
        },
      ],
    };
  },
  created() {
    console.log(process.env.NODE_ENV), "ppppp";
  },
  methods: {
    // 修改是否让页面显示与隐藏的事件
    updateVisible(val) {
      this.dialogVisible = val;
    },
    // 点击取消的事件
    resetPopupData() {
      //  这里可重置数据
      this.dialogVisible = false;
    },
    // 点击确定的按钮
    async submitPopupData() {
      this.dialogVisible = false;
    },
    // 关闭弹框（头部的X）
    handleClose() {
      this.dialogVisible = false;
    },
    // 随机背景色
    randomRgb() {
      let R = Math.floor(Math.random() * 255);
      let G = Math.floor(Math.random() * 255);
      let B = Math.floor(Math.random() * 255);
      return {
        background: "rgb(" + R + "," + G + "," + B + ")",
      };
    },
    // 获取数据
    getData(data) {
      console.log(data);
      this.dialogVisible = true;
      this.dialogTitle = data.id;
      this.content = data.contact;
    },
    changeValData(val) {
      console.log(val, "======");
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  ul {
    display: flex;
    flex-wrap: wrap;
    li {
      width: 100px;
      height: 100px;
      margin: 20px;
      cursor: pointer;
      position: relative;
    }
    span {
      display: block;
      position: absolute;
      top: 50%;
      left: 50%;
      font-weight: bold;
      color: #fff;
      transform: translate(-50%, -50%);
    }
  }
}
</style>
